using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Configuration;

namespace ZooApplication.Library
{
    public class LoginModel : ILoginModel
    {
        public bool Authenticate(string emailAddress, string password)
        {
            SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ZooDB"].ConnectionString);
            SqlCommand cmd = new SqlCommand(
                "SELECT count(EmailAddress) FROM [Profiles] " +
                "WHERE EmailAddress=@EmailAddress AND Password=@Password",
                conn);
            cmd.Parameters.AddWithValue("@EmailAddress", emailAddress);
            cmd.Parameters.AddWithValue("@Password", password);
            try
            {
                conn.Open();
                if((int)cmd.ExecuteScalar()==1) 
                    return true;

                return false;
            }
            finally
            {
                conn.Close();
            }
        }
    }
}
